from rest_framework import serializers

from goods.models import SPU, Brand


class BrandSerializer(serializers.ModelSerializer):

    class Meta:
        model = Brand
        fields = ('id', 'name')

class SPUSerializer(serializers.ModelSerializer):
    """sku表序列化器"""
    # 关联嵌套序列化返回
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()
    brand_id = serializers.IntegerField()
    brand = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = SPU
        exclude = ('category1', 'category2', 'category3')